package org.wendu.wdoa.apprev.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wendu.wdoa.apprev.dao.ApprevDao;
import org.wendu.wdoa.apprev.dto.leaveAddDto;
import org.wendu.wdoa.apprev.dto.leavequeryDto;
import org.wendu.wdoa.apprev.model.leave;
import org.wendu.wdoa.apprev.service.ApprevService;
import org.wendu.wdoa.common.page.PageParam;
import org.wendu.wdoa.common.page.PageUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ApprevServiceImpl implements ApprevService {

    @Autowired
    private ApprevDao apprevDao;


    @Override
    public Map<String, Object> getUserLeaveList(String userId, PageParam pageParam) {
        return PageUtils.getPage(pageParam,()->apprevDao.findCurrentLeaveList(userId,pageParam));
    }

    @Override
    public void insterLeave(String userId, leaveAddDto leaveAdd) {
        Integer newId = apprevDao.findNewId();
        leaveAdd.setL_id(newId);
        leaveAdd.setL_date(new Date());
        apprevDao.addNewLeave(userId,leaveAdd);
    }

    @Override
    public void updateLeave(leave leave) {
        apprevDao.updateLeave(leave);
    }

    @Override
    public void endLeave(leave leave) {
        leave.setL_back(new Date());
        apprevDao.endLeave(leave);
    }
}
